#pragma once

#include <filesystem>

#include "memdb/impl/IData.h"

namespace memdb {
namespace impl {
namespace simple {


class KvTable;

class Data : public memdb::impl::IData {
public:
  Data(const std::filesystem::path & dbpath, const std::string & name);
  ~Data() override;

public:
	std::error_code open() override;
	std::error_code close() override ;
	bool isOpened() const override;

	std::error_code destroy() override;
  bool exists() const override;

	const std::string & name() const override ;

public: 
// dml
  std::error_code insert(const std::string & key, const std::string & value) override;
  std::error_code remove(const std::string & key) override;
  std::error_code update(const std::string & key, const std::string & value) override;

  std::error_code replace(const std::string & key, const std::string & value) override;

  
// dql
  bool exists(const std::string & key) const override;
  std::error_code get(const std::string & key, std::string & value) const override;

  size_t count() const override;


	typedef IData::Item Item;
	std::unique_ptr<helper::iter::Iterator<Item>> iterator() const override;
	std::unique_ptr<helper::iter::Iterator<Item>> iterator(size_t offset, size_t len) const override;
	std::unique_ptr<helper::iter::Iterator<Item>> iterator(const std::string &key, size_t offset, size_t len) const override;

private:
  std::filesystem::path _dbpath;
	std::filesystem::path _dir;
	const std::string & _name; 
	std::unique_ptr<KvTable> _table;
};


}//namespace simple
}//namespace impl
}//namespace memdb
